<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline" style="padding-left: 5px;">
                <input type="text" name="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                       class="layui-input">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
                <input type="text" name="card_num" lay-verify="title" placeholder="Card Num" autocomplete="off"
                       class="layui-input">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <input type="text" name="app_code" lay-verify="title" placeholder="App Code" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <input type="text" name="tran_token" lay-verify="title" placeholder="Tran Token" autocomplete="off"
                   class="layui-input" value="">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <select name="tran_type" >
                <option value="">Please Select Type</option>
                {foreach $tran_type as $v_d}
                <option value="{$v_d}">{$v_d}</option>
                {/foreach}
            </select>
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <input type="text" name="datetime" id="datetime" placeholder="Start Time _ End Time" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        // laydate.render({
        //     elem: '#update_datetime',
        //     range: '_',
        //     format: 'yyyy-MM-dd'
        // });
        table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('Cards/cardPay')}",
            id: 'balanceTable',
            //where:{tran_token : $('#tran_token').val()},
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports'],
            cols: [[
                { type: 'numbers'},
                { field: 'username',  align: 'left', title: '会员',width: 180},
                { field: 'tran_token',  align: 'left', title: '消费Token',width: 150},
                { field: 'app_code',  align: 'left', title: 'AppCode',width: 110},
                { field: 'card_num', title: '卡号/卡名',
                    templet:function (d) {
                        var num = d.card_num;
                        const first_name = d.first_name;
                        const last_name = d.last_name;
                        var   html = '';
                        if(num != null){
                            html = num;
                            if(first_name != null){
                                html +=" / <span style='font-size: 15px;font-weight: bold'>"
                                    + first_name + ' ' + last_name + "</span>";
                            }
                        }else{
                            html = '--';
                        }
                        return html;
                    },align:"left",width: 180},
                { field: 'type',  align: 'left', title: '交易状态',
                    templet:function (d) {
                        const type = d.tran_type;
                        var color = '';
                        if(type == 'DECLINE'){
                            color = 'red';
                        }else if(type == 'POST'){
                            color = 'green';
                        }else if(type == 'AUTHORIZATION'){
                            color = 'gray';
                        }else if(type == 'REVERSAL'){
                            color = '#00aeef';
                        }
                        return "<span style='color:" + color + ";font-weight:bold'>" + type + "</span>"
                    },
                    totalRowText:'Total Amount:'},
                { field: 'shopping',  align: 'left', title: '商家'},
                { field: 'desc',  align: 'left', title: '备注'},
                { field: 'state',  align: 'left', title: 'State',width: 80},
                { field: 'amount',  align: 'right', title: '预扣款($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'ctime', align: 'center', title: '交易时间' ,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'amount_real',  align: 'right', title: '实际扣款($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'utime', align: 'center', title: '结算时间',
                    templet: function (d) {
                        const utime = d.utime;
                        if(utime != null){
                            return layui.util.toDateString(d.utime * 1000, "yyyy-MM-dd HH:mm:ss");
                        }else{
                            return '--';
                        }

                    }
                }
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100 ,500 ,1000],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>